package com.example.quartz.app.controller;

import com.example.quartz.app.entity.JobEntity;
import com.example.quartz.app.service.JobService;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JobController {

    @Autowired
    private JobService demoService;

    /**
     * 立即运行某个定时任务
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/runNow")
    public String runNow(JobEntity jobEntity) throws SchedulerException {
        return demoService.runNow(jobEntity);
    }

    /**
     * 停止某个定时任务
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/stopRun")
    public String stopRun(JobEntity jobEntity) throws SchedulerException {
        return demoService.stopRun(jobEntity);
    }

    /**
     * 停止所有定时任务
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/stopAll")
    public String stopAll(JobEntity jobEntity) throws SchedulerException {
        return demoService.stopAll(jobEntity);
    }

    /**
     * 启动某个定时任务
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/startRun")
    public String startRun(JobEntity jobEntity) throws SchedulerException {
        return demoService.startRun(jobEntity);
    }

    /**
     * 启动所有定时任务
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/startAll")
    public String startAll(JobEntity jobEntity) throws SchedulerException {
        return demoService.startAll(jobEntity);
    }

    /**
     * 新增定时任务并启动
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/addJob")
    public String addJob(JobEntity jobEntity) throws SchedulerException {
        return demoService.addJob(jobEntity);
    }

    /**
     * 删除定时任务并停止
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/deleteJob")
    public String deleteJob(JobEntity jobEntity) throws SchedulerException {
        return demoService.deleteJob(jobEntity);
    }

    /**
     * 修改定时任务时间并重新运行
     * @param jobEntity
     * @return
     * @throws SchedulerException
     */
    @RequestMapping("/updateJob")
    public String updateJob(JobEntity jobEntity) throws SchedulerException {
        return demoService.updateJob(jobEntity);
    }
}
